import 'package:flutter_test/flutter_test.dart';
import 'package:serial_port/serial_port.dart';
import 'package:serial_port/serial_port_platform_interface.dart';
import 'package:serial_port/serial_port_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

class MockSerialPortPlatform
    with MockPlatformInterfaceMixin
    implements SerialPortPlatform {

  @override
  Future<String?> getPlatformVersion() => Future.value('42');

  @override
  Future<bool?> close() {
    // TODO: implement close
    throw UnimplementedError();
  }

  @override
  Future<void> setLog(bool value) {
    // TODO: implement setLog
    throw UnimplementedError();
  }

  @override
  Future<bool?> start(String device, int baudrate) {
    // TODO: implement start
    throw UnimplementedError();
  }

  @override
  // TODO: implement onSerialPortDataChanged
  Stream<String> get onSerialPortDataChanged => throw UnimplementedError();
}

void main() {
  final SerialPortPlatform initialPlatform = SerialPortPlatform.instance;

  test('$MethodChannelSerialPort is the default instance', () {
    expect(initialPlatform, isInstanceOf<MethodChannelSerialPort>());
  });

  test('getPlatformVersion', () async {
    SerialPort serialPortPlugin = SerialPort();
    MockSerialPortPlatform fakePlatform = MockSerialPortPlatform();
    SerialPortPlatform.instance = fakePlatform;

    expect(await serialPortPlugin.getPlatformVersion(), '42');
  });
}
